package lanQiaoBei.violent_recursion;

import java.util.Stack;

/*
* 给定一个栈 请利用系统栈 将给定栈逆序(递归)
* 1
* 2
* 3
* */
public class ReverseStackBySystemStack {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(3);
        stack.push(2);
        stack.push(1);

        System.out.println(popBottom(stack));
//        while (!stack.isEmpty()){
//            System.out.println(stack.pop());
//        }
        realize(stack);
        while (!stack.isEmpty()){
            System.out.println(stack.pop());
        }

    }
    public static void realize(Stack<Integer>stack){
           if(stack.isEmpty())return;
           Integer bottom = popBottom(stack);
           realize(stack);
           stack.push(bottom);
    }
    public static Integer popBottom(Stack<Integer>stack){
           Integer pop = stack.pop();
           if(stack.isEmpty())return pop;
           Integer bottom = popBottom(stack);
           stack.push(pop);
           return bottom;
    }
}
